package com.foreknow.elmboot.mapper;

import com.foreknow.elmboot.po.DeliveryAddress;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
public interface DeliveryAddressMapper {
    //根据用户编号查询所属送货地址
    @Select("select * from deliveryaddress where userId=#{userId} order by daId")
    public List<DeliveryAddress> listDeliveryAddressByUserId(String userId);

    //根据送货地址编号查询送货地址
    @Select("select * from deliveryaddress where daId=#{daId}")
    public DeliveryAddress getDeliveryAddressById(Integer daId);

    //向送货地址表中添加一条记录
    @Insert("insert into deliveryaddress(contactName,contactSex,contactTel,address,userid) " +
            "values(#{contactName},#{contactSex},#{contactTel},#{address},#{userId})")
    public int saveDeliveryAddress(String contactName,Integer contactSex,String contactTel,String address,Integer userId);

    //根据送货地址编号更新送货地址信息
    @Update("update deliveryaddress " +
            "set contactName=#{contactName},contactSex=#{contactSex},contactTel=#{contactTel},address=#{address},userid=#{userId}" +
            "where daId=#{daId}")
    public int updateDeliveryAddress(Integer daId,String contactName,Integer contactSex,String contactTel,String address,Integer userId);

    //根据送货地址编号删除一条记录
    @Delete("delete from deliveryaddress " +
            "where daId=#{daId}")
    public int removeDeliveryAddress(int daId);
}
